package com.boxin.ims.modules.sys.scheduler;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boxin.framework.base.utils.DateUtils;
import com.boxin.ims.modules.wechat.service.WechatDaoHelper;

/**
 * @author Jakemanse
 * @date 2013-10-16
 * @function <p>秒杀调度器 </p>
 */
@Service
public class SeckillScheduler  extends AbstractScheduler {
	
	@Autowired
	WechatDaoHelper wechatDaoHelper;
	
	public SeckillScheduler() {
		super();
	}
	
	
	@Override
	public String frequency() {
		return  this.getSchedulerInfo().getFrequence();
	}

	
	@Override
	public void process() {
		List<Map<String,Object>> smap = wechatDaoHelper.queryAllSeckills(null);
		if(smap !=null && !smap.isEmpty()){
			for(Map m:smap){
				if(m.get("repeats")!=null &&  (Boolean)(m.get("repeats")  ) == true ){//需要重复
					if(DateUtils.getTodayString().equals(DateUtils.formatDate((Date)m.get("start_time"), "yyyyMMdd"))  
							&& DateUtils.getTodayString().equals(DateUtils.formatDate((Date)m.get("end_time"), "yyyyMMdd"))
							&& ((Date)m.get("end_time")).getTime() < new Date().getTime()){
						
						wechatDaoHelper.updateSeckillNextStartTime(m);
					}
				}
			}
		}
		
	}

}
